# encoding=utf-8
# click模块用于生成命令行提示
import click

from core.deal_shell.dealProcessShell import dealProcessShell
from core.deal_file.dealSampleSheet import dealSampleSheet
from core.deal_file.dealDir import dealDir
from core.deal_file.dealStatFile import dealStatFile
from core.deal_shell.dealWorkShell import dealWorkShell
from core.deal_shell.dealPipelineShell import dealPipelineSell



# 添加命令行提示信息 
@click.command()
@click.option('-ss', '--samplesheet', required=True, type=str, help="samplesheet file of bcl2fastq")
@click.option('-id', '--inputdir', required=True, type=str, help="directory of bcl")
@click.option('-st', '--sextype', required=True, type=str, help="sample sex and type infomation")
@click.option('-ba', '--blastall', default='false', type=str, help="default blast 100k reads")
@click.option('-c', '--cpu', default=18, type=int, help="threads of all programs")

def main(samplesheet, inputdir, sextype, blastall, cpu):
    #########预处理###################
    # 处理samplesheet
    _samples, _lane = dealSampleSheet(samplesheet)
    # 生成流程所需文件夹
    bclDir,runid,outdir,fqDir,shellDir,L01Dir = dealDir(inputdir,_samples)
    # 生成Sequence.txt
    samplesDir, rawSamplesDir = dealStatFile(inputdir,fqDir,_samples,_lane)
    ########脚本生成##################
    # 生成work.sh以及all.cnv.sh
    dealWorkShell(shellDir,L01Dir,_samples,_lane,bclDir,runid,outdir,rawSamplesDir)
    # 生成流程中的脚本
    runbwa,runkraken,runrgi,runmyco,runkkbwa,runntbwa,mergekraken,sex = dealProcessShell(shellDir,samplesDir,rawSamplesDir,outdir,fqDir,runid,blastall,sextype,cpu)
    # pipeline.sh 写入命令
    dealPipelineSell(samplesheet,runid,shellDir,outdir,fqDir,sextype,runbwa,runkraken,runrgi,runmyco,runkkbwa,runntbwa,mergekraken,sex)

if __name__ == '__main__':
    main()
